var ming = document.getElementById("ming");
var cook = document.cookie;
var arr = cook.split("; ");
var uid = 0;
var token1 = 0;
var id =0;
var token = 0;
var name = 0;
for (var i = 0; i < arr.length; i++) {
    var newArr = arr[i].split("=");
    if (newArr[0] == "id") {
        id = newArr[0];
        uid = newArr[1];
    }
    if (newArr[0] == "token") {
        token = newArr[0];
        token1 = newArr[1];
    }
    if (newArr[0] == "usename") {
        name = newArr[0];
        var strr = `
      <a href="login.html" id="ming">${newArr[1]}</a>&nbsp;&nbsp;&nbsp;
      <a href="" id="tc" >退出</a>
      `;
        tui.innerHTML = strr;
        $("#tc").click(function () {
            
            var oDate = new Date();
            oDate.setDate(oDate.getDate() - 1);
            document.cookie = id + "=" + uid + ";expires=" + oDate;
            document.cookie = name + "=" + newArr[1] + ";expires=" + oDate;
            document.cookie = token + "=" + token + ";expires=" + oDate;
            var strr = `
            <a href="login.html" id="ming">请登录</a>
            `;
              tui.innerHTML = strr;
              alert("退出登录！")
        });
    }
}
if (uid != 0) {
    var sp = document.getElementById("sp");
    var shu = document.getElementById("shu");
    
    $.get("http://jx.xuzhixiang.top/ap/api/productlist.php", {
        uid: uid
    }, data => {
        // var str2 = "";
        // for (var i = 1; i < 6; i++) {
        //     str2 += `
        //     <div class="sp-p">
        //         <a href="deta.html?id=${data.data[i].pid}" class="tiao"><img src="../${data.data[i].pimg}" alt=""></a>
        //         <p class="qi"><i>￥</i>${data.data[i].pprice}</p>
        //         <p class="ming"><a href="">${data.data[i].pname}</a></p>
        //         <a href="">天猫国际进口超市</a><br>
        //         <span>该款月成交 <em>5238笔</em></span>
        //     </div>
        // `;

        // }
        // sp.innerHTML = str2;

        // let e = Math.ceil(data.data.length/5);
        // let se = "";
        // for(var i =0; i<e;i++){
        //     se +=`
        //     <span>${i+1}</span>
        //     `;
        // }
        // shu.innerHTML = se;

        var t = data.data.length; //总数据
        var a = Math.ceil(t / 5); //5个一页共多少页
        var str = ""; //存放页码
        for(var i =1; i<= a;i++){
            str +=`
                <span>${i}</span>
            `;
        }
        shu.innerHTML = str;

        var strr22 = "";
        for(let i = 0; i < 5; i++){
            strr22 += `
            <div class="sp-p">
                <a href="deta.html?id=${data.data[i].pid}" class="tiao"><img src="../${data.data[i].pimg}" alt=""></a>
                <p class="qi"><i>￥</i>${data.data[i].pprice}</p>
                <p class="ming"><a href="">${data.data[i].pname}</a></p>
                <a href="">天猫国际进口超市</a><br>
                <span>该款月成交 <em>5238笔</em></span>
            </div>
        `;
        }
        sp.innerHTML = strr22;
        
        
        $(".shu").children().click(function() {
            var c = $(this).index();
            var strr22 = "";
            for(let i = c *5; i < Math.min((c *5)+5, t); i++){
                strr22 += `
                <div class="sp-p">
                    <a href="deta.html?id=${data.data[i].pid}" class="tiao"><img src="../${data.data[i].pimg}" alt=""></a>
                    <p class="qi"><i>￥</i>${data.data[i].pprice}</p>
                    <p class="ming"><a href="">${data.data[i].pname}</a></p>
                    <a href="">天猫国际进口超市</a><br>
                    <span>该款月成交 <em>5238笔</em></span>
                </div>
            `;
            }
            sp.innerHTML = strr22;
        });



    });
}
